package com.kfm.base.string;

public class Exer01 {

    public static void main(String[] args) {
        String str = "a1bb2c3d4489h";

        count1(str);
    }

    private static void count1(String str) {
        int letterCount = 0;
        int digitCount = 0;
        for (int i = 0; i < str.length(); i++) {
            Character c = str.charAt(i);
            String sub = str.substring(i, i + 1);
            if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
                letterCount++;
            } else if (c >= '0' && c <= '9') {
                digitCount ++;
            }
        }

        System.out.println("字母有： " + letterCount + " 个");
        System.out.println("数字有： " + digitCount + " 个");
    }

    private static void count(String str) {
        int letterCount = 0;
        int digitCount = 0;
        for (int i = 0; i < str.length(); i++) {
            Character c = str.charAt(i);
            String sub = str.substring(i, i + 1);
            if (Character.isLetter(c)) {
                letterCount++;
            } else if (Character.isDigit(c)) {
                digitCount ++;
            }
        }

        System.out.println("字母有： " + letterCount + " 个");
        System.out.println("数字有： " + digitCount + " 个");
    }
}

